//
//  ZpMainViewController.m
//  WeiBo_OC
//
//  Created by MacBook Pro on 16/5/23.
//  Copyright © 2016年 MacBook Pro. All rights reserved.
//

#import "ZpMainViewController.h"
#import "ZpDisCoverTableViewController.h"
#import "ZpHomeTableViewController.h"
#import "ZpMessageTableViewController.h"
#import "ZpProfileTableViewController.h"
#import "ZpBaseNavigationController.h"
#import "ZpMainTabBar.h"
@interface ZpMainViewController ()

@end

@implementation ZpMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // 添加孩子控制器
    [self setChildControllers];
    // 使用KVC，将TabBar设置自己定义的，
    [self setValue:[ZpMainTabBar new] forKey:@"tabBar"];
}

- (void)setChildControllers{
    
    [self setChildControllerTitle:@"首页" andImageName:@"tabbar_home" andController:[[ZpHomeTableViewController alloc] init]];
    [self setChildControllerTitle:@"发现" andImageName:@"tabbar_discover" andController:[[ZpDisCoverTableViewController alloc] init]];
    [self setChildControllerTitle:@"消息" andImageName:@"tabbar_message_center" andController:[[ZpMessageTableViewController alloc] init]];
    [self setChildControllerTitle:@"我的" andImageName:@"tabbar_profile" andController:[[ZpProfileTableViewController alloc] init]];
}

- (void)setChildControllerTitle:(NSString *)title andImageName:(NSString *)imageName andController:(UIViewController *)vc{
    
    ZpBaseNavigationController *nav = [[ZpBaseNavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
    
    
    vc.title = title;
//    vc.tabBarItem.title = title;
//    vc.navigationItem.title = title;
    
    vc.tabBarItem.image = [UIImage imageNamed:imageName];
    NSString *selectImageName = [NSString stringWithFormat:@"%@_selected",imageName];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];


    
    
    vc.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -2);
    vc.tabBarItem.imageInsets = UIEdgeInsetsMake(0, 0, 1, 0);
    
    
}

+ (void)initialize{

    UITabBarItem *item = [UITabBarItem appearance];
    
    
    [item setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12]} forState:UIControlStateNormal];

    [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor greenColor]} forState:UIControlStateNormal];
    
    
    [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor orangeColor]} forState:UIControlStateSelected];
    


    



}




@end
